package com.gomefinance.hl.elasticjob;

import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import com.gomefinance.hl.elasticjob.config.JavaJobConfig;
import com.gomefinance.hl.elasticjob.job.dataflow.JavaDataflowJob;
import com.gomefinance.hl.elasticjob.util.YmlUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * <h2>使用原始java 的方式配置和使用elasticJob 定时任务</h2>
 * 1.配置并创建注册中心 zookeeper    <br/>
 * 2.创建编写job处理类 <br/>
 * 3.创建并配置job的作业控制器scheduler<br/>
 *
 * @Author hzj
 * @Date 2017/8/23 16:56
 * @Description :
 */
@Slf4j
public class JavaElasticJobMain {

    public static void main(String[] args) {
        //yml配置的属性
        YmlUtils ymlUtils = YmlUtils.getInstance();
        String serverList = (String) ymlUtils.getPropertics("regCenter.serverList");
        String namespace = (String) ymlUtils.getPropertics("regCenter.namespace");
        String shardingCron = (String) ymlUtils.getPropertics("dataflowJob.cron");
        Integer shardingCount = (Integer) ymlUtils.getPropertics("dataflowJob.shardingTotalCount");
        String shardingItems = (String) ymlUtils.getPropertics("dataflowJob.shardingItemParameters");

        //配置并开启注册中心
        ZookeeperRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration(serverList, namespace));
        zookeeperRegistryCenter.init();

        //配置并开启任务控制器 scheduler
        JavaJobConfig javaJobConfig = new JavaJobConfig();
        JobScheduler scheduler = javaJobConfig.dataflowJobScheduler(JavaDataflowJob.class, shardingCron, shardingCount, shardingItems, zookeeperRegistryCenter);
        scheduler.init();
    }


}
